﻿using RpcModel;
using RpcSync.Collect;
using RpcSync.Collect.Model;
using RpcSync.Model;
using RpcSync.Service.Interface;

namespace RpcSync.Service.Broadcast
{
    /// <summary>
    /// 加载集群下的所有节点
    /// </summary>
    [RpcClient.Attr.UnityName("AllMerNode")]
    internal class LoadALLMerNode : IInitBroadcast
    {
        private IRemoteServerGroupCollect _Server;
        public LoadALLMerNode(IRemoteServerGroupCollect server)
        {
            _Server = server;
        }
        public void InitBroadcastBody(BroadcastMsg msg, MsgSource source, ref BroadcastBody body)
        {
            long rpcMerId = msg.RpcMerId == 0 ? source.RpcMerId : msg.RpcMerId;
            MerServer[] servers = this._Server.GetAllServer(rpcMerId);
            body.RpcMerId = rpcMerId;
            body.ServerId = servers.GetAllServer(msg.RegionId);
        }
    }
}
